package com.atguigu.dga.common;


import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

//根据 名称获得组件实例
@Component
public class SpringBeanProvider implements ApplicationContextAware {

     ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext=applicationContext;
    }

    public <T>   T  getBeanByName(String beanName ,Class<T> tClass){
       return applicationContext.getBean(beanName, tClass);
    }

}
